package com.gm.oa.util;

public class GMDaoUtils {

	
	public final static String DBNAME_ORACLE = "oracle";
	public final static String DBNAME_MYSQL = "mysql";
	public final static String DBNAME_SQLSERVER = "sqlserver";	

	/**
	 * 生成翻页SQL语句,执行生成的SQL语句,得到要显示的数据集
	 * @param
	 * pageId为页码,itemCount为每页要显示的项数,strSql为查询数据的SQL语句,dbName为数据库名，目前支持oracle,mysql
	 */
	public static String buildPageSql(String pageId, String itemCount,String strSql,String dbName) {
		String returnStr = "";
        dbName = dbName.toLowerCase();
		
		if (DBNAME_ORACLE.equals(dbName)) {
			returnStr = "select * from ( "
					+ "select row_.*, rownum rownum_ from ("
					+ strSql
					+ ") row_ where rownum <="
					+ (Integer.parseInt(pageId) * Integer.parseInt(itemCount))
					+ ") where rownum_ >="
					+ ((Integer.parseInt(pageId) - 1)* Integer.parseInt(itemCount) + 1);
		}else if(DBNAME_MYSQL.equals(dbName)){
			returnStr = strSql + " limit "+((Integer.parseInt(pageId)-1) * Integer.parseInt(itemCount))+","+itemCount;
		}
		return returnStr;
	}
}
